import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
import {
  project,
  allTag
} from '../../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    interest: [{
      name: 'java'
    }, ],
    arr: []
  },
  getAllTag() {
    allTag().then(res => {
      console.log(res);
      this.setData({
        interest: res.data
      })
    })
  },
  addProject() {
    let tags = this.data.arr.toString()
    // console.log(tags);
    // console.log(tags.length);
    if (tags.length === 0) {
      Toast.fail('请为项目添加个性标签吧！');
      return 0;
    } else {
      // project(projectId,).then((res)=>{

      // })
      return 1;
    }

  },
  checkLabs(e) {
    let that = this,
      index = e.currentTarget.dataset.index,
      value = e.currentTarget.dataset.value,
      tagsId = e.currentTarget.dataset.id,
      items = that.data.interest,
      arr = that.data.arr,
      val = items[index].checked, //点击前的值
      limitNum = 10,
      curNum = 0; //已选择数量
    //选中累加
    for (var i in items) {
      if (items[i].checked) {
        curNum += 1;
      }
    }
    if (!val) {
      if (curNum == limitNum) {
        wx.showModal({
          content: '选择数量不能超过' + limitNum + '个',
          showCancel: false
        })
        return;
      }
      arr.push(tagsId);
    } else {
      for (var i in arr) {
        if (arr[i] == tagsId) {
          arr.splice(i, 1);
        }
      }
    }
    items[index].checked = !val;
    that.setData({
      interest: items,
      arr: arr
    })

  },
  toAddTeam: function () {
    Dialog.confirm({
        title: '提示',
        message: '你的项目标签已添加，是否为项目生创建团队？',
      })
      .then(() => {
        // console.log(this.addProject())
        if(this.addProject()){
          wx.navigateTo({
          url: '../addTeam/addTeam',
        })
        }
      })
      .catch(() => {
        wx.switchTab({
          url: '../add/add',
        })
      });

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAllTag()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})